package com.fivetiger.service.impl;


import com.fivetiger.dao.NurseDao;
import com.fivetiger.entity.Nurse;
import com.fivetiger.service.inte.NurseService;
import com.fivetiger.util.RUtil;
import com.fivetiger.vo.PageBean;
import com.fivetiger.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Service //IOC
public class NurseServiceImpl implements NurseService {
    @Autowired
    private NurseDao nurseDao;
    @Override
    public R save(Nurse nurse) {
        if(nurseDao.insert(nurse)>0){

            return RUtil.ok();
        }else {
            return RUtil.fail();
        }
    }

    @Override
    public PageBean queryPage() {
        List<Nurse> list=nurseDao.selectAll();
        return new PageBean(0,"",list.size(),list);
    }

    @Override
    public R saveBatch(MultipartFile file) {
        //1.校验
//        if(!file.isEmpty()){
//            //2.获取文件内容
//            try {
//                InputStream is=file.getInputStream();
//                //3.实例化自定义监听器
//                MasterReadListener masterReadListener=new MasterReadListener();
//                //4.解析Excel
//                List<Master>list= EasyExcel.read(is,Master.class,masterReadListener).doReadAllSync();
//                //5.获取解析的结果,执行批处理
//                if(masterDao.insertBatch(list)>0){
//                    return RUtil.ok(0);
//                }
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//        }
        return RUtil.fail();
    }

    @Override
    public R saveBatchV2(MultipartFile file) {
        return null;
    }

    @Override
    public R change(Nurse nurse) {
        if (nurseDao.update(nurse)>0){
            return RUtil.ok();
        }else {
            return RUtil.fail();
        }
    }
}
